package com.leetcode.dataStruct.tree;

import com.leetcode.dataStruct.TreeNode;

public class HasPathSum {
    public static void main(String[] args) {

    }

    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        if (root.left == null && root.right == null) {
            return targetSum == root.val;
        }
        boolean leftIsOk = hasPathSum(root.left, targetSum - root.val);
        boolean rightIsOk = hasPathSum(root.right, targetSum - root.val);
        return leftIsOk || rightIsOk;
    }
}
